#ifndef DLM_H
#define DLM_H


#define DLM_OPEN_OK 0
#define DLM_OPEN_ERR 1

#define DLM_ADD_RES_OK 0
#define DLM_ADD_RES_ERR 1
#define DLM_ADD_RES_EXISTS 2

#define DLM_DEL_RES_OK 0
#define DLM_DEL_RES_ERR 1
#define DLM_DEL_RES_NOT_EXISTS 2

#define DLM_LOCK_OK 0
#define DLM_LOCK_ERR 1
#define DLM_LOCK_EXISTS 2
#define DLM_LOCK_TIMEOUT 3

#define DLM_TRYLOCK_OK 0
#define DLM_TRYLOCK_ERR 1
#define DLM_TRYLOCK_NOT_EXISTS 2
#define DLM_TRYLOCK_FAILED 3

#define DLM_UNLOCK_OK 0
#define DLM_UNLOCK_ERR 1
#define DLM_UNLOCK_NOT_EXISTS 2

#define DLM_CLOSE_OK 0
#define DLM_CLOSE_ERR 1

#define DLM_LOCK_CR 0
#define DLM_LOCK_CW 1
#define DLM_LOCK_PR 2
#define DLM_LOCK_PW 3
#define DLM_LOCK_EX 4

typedef struct{
    int processFifo;
    int processId;
    int serverFifo;
} dlm_t;

#ifdef __cplusplus
extern "C" {
#endif

    int DLM_open(dlm_t* dlm, char const* fifoFullPath);
    int DLM_add_resource(dlm_t* dlm, const int resourceId);
    int DLM_del_resource(dlm_t* dlm, const int resourceId);
    int DLM_lock(dlm_t* dlm, const int resourceId, const int lockType, const long timeoutInNanosec);
    int DLM_unlock(dlm_t* dlm, const int resourceId);
    int DLM_trylock(dlm_t* dlm, const int resourceId, const int lockType);
    int DLM_close(dlm_t* dlm);

#ifdef __cplusplus
}
#endif

#endif // DLM_H
